//
//  DeviceInfo.m
//  IPTV
//
//  Created by Echo on 13-12-5.
//  Copyright (c) 2013年 游强. All rights reserved.
//

#import "DeviceInfo.h"
#import "Global.h"


@implementation DeviceInfo
@synthesize type;
@synthesize name, fileid;
@synthesize keyArray;
@synthesize position;

#pragma mark NSCoding Methods
- (id)initWithType:(DEVICE_TYPE)atype name:(NSString*)aname fileid:(NSString*)afileid{
    type = atype;
    self.name = [Global enToChina:aname];
    if ([afileid length] > 0) {
        self.fileid = afileid;
    }
	if ((self = [super init])) {
        keyArray = [[NSMutableArray alloc] init];
        if (type == DEVICE_AIR){
            for (int i=0; i<6; i++) {
                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
                if (i == 0) {
                    dataInfo.airType  = AIR_ON;
                }else if (i == 1) {
                    dataInfo.airType  = AIR_OFF;
                }else if (i == 2) {
                    dataInfo.airType  = AIR_COLD;
                }else if (i == 3) {
                    dataInfo.airType  = AIR_HOT;
                }
                else if (i == 4) {
                    dataInfo.airType  = AIR_DAMP;
                }
                else if (i == 5) {
                    dataInfo.airType  = AIR_GAS;
                }else if (i == 6) {
                    dataInfo.airType  = AIR_AUTO;
                }
                [keyArray addObject:dataInfo];
            }
        }else if (type == DEVICE_SOUND){
            for (int i=0; i<13; i++) {
                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
                [keyArray addObject:dataInfo];
            }
        }else if (type==DEVICE_TV || type==DEVICE_STB){
            for (int i=0; i<30; i++) {
                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
                [keyArray addObject:dataInfo];
            }
        }else if (type==DEVICE_SOCKET1){
            for (int i=0; i<1; i++) {
                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
                [keyArray addObject:dataInfo];
            }
        }else if (type==DEVICE_SOCKET2){
            for (int i=0; i<3; i++) {
                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
                [keyArray addObject:dataInfo];
            }
        }else if (type==DEVICE_SOCKET3){
            for (int i=0; i<4; i++) {
                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
                [keyArray addObject:dataInfo];
            }
        }else{
//            for (int i=0; i<30; i++) {
//                NSDataInfo *dataInfo = [[NSDataInfo alloc] init];
//                if (i == 0) {
////                    dataInfo.isStudy = YES;
//                }else if (i == 5) {
////                    dataInfo.isStudy = YES;
//                }
//                [keyArray addObject:dataInfo];
//            }
        }
        
	}
	return self;
}
- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeInt:type forKey:@"type"];
	[encoder encodeObject:name forKey:@"name"];
    [encoder encodeObject:fileid forKey:@"fileid"];
    [encoder encodeObject:keyArray forKey:@"keyArray"];
    [encoder encodeInt:position forKey:@"position"];
}

- (id)initWithCoder:(NSCoder *)decoder{
	self=[super init];
    self.type = [decoder decodeIntForKey:@"type"];
    self.name = [decoder decodeObjectForKey:@"name"];
    self.fileid = [decoder decodeObjectForKey:@"fileid"];
    self.keyArray = [decoder decodeObjectForKey:@"keyArray"];
    self.position = [decoder decodeIntForKey:@"position"];
	return self;
}
@end


